<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<<<<<<< HEAD
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
=======
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
<%@page contentType="text/html; charset=utf-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
<<<<<<< HEAD
    <title>书籍修改</title>
=======
    <title>书籍添加</title>
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/back/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/back/css/xadmin.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/back/js/jquery-3.5.1.js"></script>
    <script src="${pageContext.request.contextPath}/static/back/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/back/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">

    <form class="layui-form">
        <input type="hidden" id="img" name="img" value=""/>
<<<<<<< HEAD
        <input type="hidden" id="id" name="id" value="${book.getId()}">
=======
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
        <div class="layui-row">
            <div class="layui-col-md5">
                <div class="layui-form-item">
                    <label for="bookName" class="layui-form-label">
                        <span class="x-red">*</span>书籍名
                    </label>
                    <div class="layui-input-inline">
<<<<<<< HEAD
                        <input type="text" id="bookName" name="bookName" required="" lay-verify="required"
                               autocomplete="off" class="layui-input" value="${book.getBookName()}">
                    </div>
                </div>
=======
                        <input type="text" id="bookName" name="bookName" required="" lay-verify="bookName"
                               autocomplete="off" class="layui-input" value="${bookforup.bookName}">
                    </div>
                </div>

>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                <div class="layui-form-item">
                    <label for="category" class="layui-form-label">
                        类型
                    </label>
                    <div class="layui-input-inline">
                        <select id="category" name="bookCategory.id">
<<<<<<< HEAD
                            <c:forEach items="${categories}" var="category">
                                <option value="${category.id}">${category.categoryName} </option>
=======
                            <c:forEach items="${bookCategory}" var="category">
                                <option value="${category.id}">${category.categoryName}</option>
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                            </c:forEach>
                        </select>
                    </div>
                </div>
<<<<<<< HEAD

=======
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                <div class="layui-form-item">
                    <label for="author" class="layui-form-label">
                        作者
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="author" name="author" required="" lay-verify="author"
<<<<<<< HEAD
                               autocomplete="off" class="layui-input" value="${book.getAuthor()}">
=======
                               autocomplete="off" class="layui-input" value="${bookforup.author}">
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="publisher" class="layui-form-label">
                        出版社
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="publisher" name="publisher" required="" lay-verify="publisher"
<<<<<<< HEAD
                               autocomplete="off" class="layui-input" value="${book.getPublisher()}">
=======
                               autocomplete="off" class="layui-input" value="${bookforup.publisher}">
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="publisher" class="layui-form-label">
                        出版时间
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="publishTime" name="publishTime" required="" lay-verify="publisher"
<<<<<<< HEAD
                               autocomplete="off" class="layui-input" value="${publishTimeFormat}">
=======
                               autocomplete="off" class="layui-input" value="">
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="price" class="layui-form-label">
                        价格
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="price" name="price" required="" lay-verify="price"
<<<<<<< HEAD
                               placeholder="￥" autocomplete="off" class="layui-input" value="${book.getPrice()}">
=======
                               placeholder="￥" autocomplete="off" class="layui-input" value="${bookforup.price}">
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="price" class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn" id="upload_btn">
<<<<<<< HEAD
                            <i class="layui-icon">&#xe67c;</i>修改上传的图片
                        </button>
                    </div>
                </div>

=======
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                    </div>
                </div>
            <input type="hidden" name="id" value="${bookforup.id}"/>
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                <div class="layui-form-item">
                    <label for="price" class="layui-form-label">
                    </label>
                    <button class="layui-btn" lay-filter="update" lay-submit="">
                        修改
                    </button>
                </div>
            </div>
            <div class="layui-col-md7">
<<<<<<< HEAD
                <img id="showImg" style="width: auto;height:auto;max-width: 100%;max-height: 400px" src="/${book.getImg()}"/>
=======
                <img id="showImg" style="width: auto;height:auto;max-width: 100%;max-height: 400px" src="${bookforup.img}"/>
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
            </div>
        </div>
    </form>

</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#publishTime',//指定元素
            format:'yyyy-MM-dd',
<<<<<<< HEAD
            max:0,
            trigger:'click'
=======
            max:0
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
        });
    });

    layui.use('upload', function () {
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_btn' //绑定元素
            , field:'file'
            , url: '${pageContext.request.contextPath}/back/upload' //上传接口
            , done: function (res) {
                if (res.code == 100) {
                    layer.msg(res.msg, {icon: 1, time: 2000});
                    $("#img").val(res.data);
<<<<<<< HEAD
                    $("#showImg").attr('src', '${pageContext.request.contextPath}/' + res.data)
=======
                    $("#showImg").attr('src', res.data)
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                }
            }
            , error: function () {
                //请求异常回调
            }
        });
    })

    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        let form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        form.verify({
<<<<<<< HEAD
            author: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(value === ''){
                    return "作者必填!"
                }
            }
        });

        //监听提交
        form.on('submit(update)', function (data) {
            //发异步，把数据提交给java 后端进行处理
            $.ajax({
                url: "${pageContext.request.contextPath}/back/alterBook",
=======

        });

        //监听提交修改
        form.on('submit(update)', function (data) {
            //发异步，把数据提交给java 后端进行处理
            $.ajax({
                url: "${pageContext.request.contextPath}/back/updatebook",
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
                type: "post",
                data: data.field,
                dataType: "json",
                success: function (res) {
                    if(res.code === 100){
                        layer.alert(res.msg, {icon: 6 },function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            // 刷新父级页面
                            parent.location.replace(parent.location.href);
                        });
                    }else{
                        layer.msg(res.msg);
                    }
                }
            })
            return false;
        });


    });
</script>

<<<<<<< HEAD
<script type="text/javascript">
    $("#category").val("${book.getBookCategory().getId()}");
    layui.form.render();
</script>

=======
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
</body>

</html>